 /*++

Copyright (c) Microsoft Corporation. 
 
This source code is subject to terms and conditions of the Microsoft
Public License. A copy of the license can be found in the License.txt
file at the root of this distribution. By using this source code in 
any fashion, you are agreeing to be bound by the terms of the Microsoft
Public License.
 
You must not remove this notice, or any other, from this software.

Module Name:

    WpdObjectProperties.h

Abstract:

    This module contains the type definitions for the WpdObjectProperties 
    helper class used to store/retrieve Sensor properties/data
--*/

#pragma once

#define DEVICE_PROTOCOL_VALUE                             L"Sensor Protocol ver 1.00"
#define DEVICE_FIRMWARE_VERSION_VALUE                     L"1.0.0.0"
#define DEVICE_POWER_LEVEL_VALUE                          100
#define DEVICE_MODEL_VALUE                                L"GenericSerialDriver"
#define DEVICE_FRIENDLY_NAME_VALUE                        L"Generic Serial Driver"
#define DEVICE_MANUFACTURER_VALUE                         L"Sensors Team"
#define DEVICE_SERIAL_NUMBER_VALUE                        L"01234567890123-45676890123456"
#define DEVICE_SUPPORTS_NONCONSUMABLE_VALUE               TRUE

//
// Update interval range in milliseconds
//
#define SENSOR_UPDATE_INTERVAL_MIN	10		// milliseconds
#define SENSOR_UPDATE_INTERVAL_MAX	60000	// milliseconds
#define SENSOR_UPDATE_INTERVAL_STEP 1		// milliseconds
//#define INTERVAL_DATA_LENGTH        5   // count of bytes for interval
#define INTERVAL_DATA_LENGTH        6   // count of bytes for interval + NUL

#include "Accelerometer2D.h" 
#include "Accelerometer3D.h" 
#include "TemperatureSensor.h" 
#include "ProximitySensor.h" 
#include "PresenceSensor.h" 
#include "CompassSensor.h" 

// Forward reference
class SensorBaseDriver;
class RS232Target;
           
HRESULT AddSupportedPropertyKeys(LPCWSTR                        wszObjectID,
                                 IPortableDeviceKeyCollection*  pKeys);

VOID AddCommonPropertyKeys(IPortableDeviceKeyCollection* pKeys);
VOID AddDevicePropertyKeys(IPortableDeviceKeyCollection* pKeys);

HRESULT AddSupportedDataFieldKeys(LPCWSTR                        wszObjectID,
                                 IPortableDeviceKeyCollection*  pKeys);

class WpdObjectProperties
{
public:
    WpdObjectProperties();
    virtual ~WpdObjectProperties();

    HRESULT Initialize( SensorBaseDriver* pBaseDriver);

    HRESULT OnGetSupportedProperties(
        __in LPWSTR  wszObjectID,
        IPortableDeviceKeyCollection** ppPortableDeviceKeyCollection
        );

    HRESULT OnGetSupportedDataFields(
        __in LPWSTR  wszObjectID,
        IPortableDeviceKeyCollection** ppPortableDeviceKeyCollection
        );

    HRESULT OnGetPropertyValues(
        __in LPWSTR  wszObjectID,
        IPortableDeviceKeyCollection* pKeys,
        IPortableDeviceValues** ppPortableDeviceValues
        );

    HRESULT OnGetDataFields(
        __in LPWSTR  wszObjectID,
        IPortableDeviceKeyCollection* pKeys,
        IPortableDeviceValues** ppPortableDeviceValues
        );

    HRESULT OnSetPropertyValues(
        __in LPWSTR  wszObjectID,
        IPortableDeviceValues* pValues,
        IPortableDeviceValues** ppResults
        );

    HRESULT OnGetAllPropertyValues(
        IPortableDeviceValues*  pParams,
        IPortableDeviceValues*  pResults
        );

    HRESULT OnGetPropertyAttributes(IPortableDeviceValues*  pParams,
                                    IPortableDeviceValues*  pResults);

    HRESULT OnDeleteProperties(IPortableDeviceValues*  pParams,
                               IPortableDeviceValues*  pResults);

    BOOL IsValidUpdateInterval(DWORD dwInterval);

    HRESULT SendUpdateIntervalToDevice(DWORD dwNewInterval);

    ULONG GetSamplingRate();
    VOID SetSamplingRate(ULONG ulRate);

	HRESULT UpdateSensorReadingForObject(
		LPCWSTR     wszObjectID, 
		LONGLONG	llSensorReading);

private:
    HRESULT GetPropertyValuesForObject(LPCWSTR                        wszObjectID,
                                       IPortableDeviceKeyCollection*  pKeys,
                                       IPortableDeviceValues*         pValues);

    HRESULT GetDataValuesForObject(LPCWSTR                        wszObjectID,
                                       IPortableDeviceKeyCollection*  pKeys,
                                       IPortableDeviceValues*         pValues);

    HRESULT GetPropertyAttributesForObject(LPCWSTR                wszObjectID,
                                           const PROPERTYKEY&     Key,
                                           IPortableDeviceValues* pAttributes);

	HRESULT AddSupportedPropertyKeys(
		LPCWSTR							wszObjectID,
		IPortableDeviceKeyCollection*	pKeys);

	HRESULT AddSupportedDataFieldKeys(
		LPCWSTR                        wszObjectID,
		IPortableDeviceKeyCollection*  pKeys);

    ULONG				m_SamplingRate;	//Used to record the interval prop

	// This critical section protects the sampling rate from concurrent access
    CComAutoCriticalSection  m_SamplingRateCriticalSection;

	LONGLONG			m_llSensorReading; //Used to receive the Sensor reading

	// sensor objects
	Accelerometer2D*	m_pAccelerometer2D;
	Accelerometer3D*	m_pAccelerometer3D;
	TemperatureSensor*	m_pTemperatureSensor;
	ProximitySensor*	m_pProximitySensor;
	PresenceSensor*		m_pPresenceSensor;
	CompassSensor*		m_pCompassSensor;

public:
    SensorBaseDriver* m_pBaseDriver;
    RS232Target*      m_pTarget; //Used to write interval prop to firmware

};

